
import React, { Component } from 'react';
import { CartItem } from './CartItem.component';
import { store } from './store/index';


export default class CartList extends Component {
    constructor(props: {}) {
        super(props);
        store.subscribe(this.updateState.bind(this));
    }

    readonly state = store.getState().cartReducer;

    render() {
        return (
            <div>
                {
                    this.state.list.map(item => {
                        return <CartItem data={item} />
                    })
                }
            </div>
        )
    }

    updateState() {
        console.log(store.getState());
        
        this.setState(store.getState().cartReducer);
    }
}